<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>
        修改密码
    </title>
    <%@include file="../../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/system/member/member_form.css">
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form id="pwdForm" class="layui-form mt20" method="post" action="${ctx}${not empty isGroup? '/member/group/updatePwd.do' : '/system/member/updatePwd.do'}">
                <input type="hidden" name="id" value="${memberId}"/>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <span style="color: #aaa">密码只能输入字母或数字</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">新密码<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="password" class="layui-input" name="password" lay-verify="password"
                                   placeholder="新密码"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">确认密码<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="password" class="layui-input" name="repassword"
                                   lay-verify="repassword" placeholder="再次确认密码"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-danger" lay-submit lay-filter="pwdForm">立即修改</button>
                            <button type="reset" class="layui-btn layui-btn-primary" onclick="javascript:history.back();">取消</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>
<script>
    $(function () {
        layui.use(['form', 'laydate', 'element'], function () {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                password: function (value) {
                    if (value == "") {
                        return "密码不能为空";
                    } else if (!util.checkPassword(value)) {
                        return "密码格式不正确";
                    }
                },
                repassword: function (value) {
                    var pwd = $("#pwdForm [name=password]").val();
                    if (value == "") {
                        return "确认密码不能为空";
                    } else if (!util.checkPassword(value)) {
                        return "确认密码格式不正确";
                    } else if (pwd != value) {
                        return "确认密码与新密码不匹配";
                    }
                }
            });

            //监听提交 修改密码
            form.on('submit(pwdForm)', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#pwdForm").attr("action");
                    $.post(action, $('#pwdForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess('密码修改成功', function () {
                                javascript:history.back();
                            });
                        } else {
                            util.layerMsgError("密码修改失败")
                        }
                    });
                });
                return false;
            });
        });
    })
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '修改密码',
            curr: true
        }],
        btns: [{
            name: '返回',
            href: 'javascript:history.back();',
            icon: 'back'
        }]
    });
</script>
</body>
</html>